#include <iostream>
#include <memory>
#include <string>

#include "thread_pool.h"

using namespace std;

class NodeA : public enable_shared_from_this<NodeA>{
 public:
    NodeA() = default;
    virtual ~NodeA() = default;

    int Run(pthread_t id) { cout << "run NodeA " << num << endl; }

 private:
    int num = 8;
};

class NodeB : public enable_shared_from_this<NodeB> {
 public:
    NodeB() = default;
    virtual ~NodeB(){
        cout << "jjjjjjjj" << endl;
    }

    int Run(pthread_t id) {
        cout << "run NodeB " << num << endl;
        cout << "line:" << __LINE__ << " " << this->shared_from_this().use_count() << endl;
        return 0;
    }

 private:
    std::string num = "==========";
};

int main(int argc, char **argv) {
    qsm::ThreadPool threadPool("test");
    shared_ptr<NodeA> testA = make_shared<NodeA>();
    shared_ptr<NodeB> testB = make_shared<NodeB>();

    threadPool.Commit(bind(&NodeA::Run, testA, placeholders::_1));
    threadPool.Commit(bind(&NodeB::Run, testB, placeholders::_1));
    cout << "B:" << testB.use_count() << std::endl;
    testB.reset();
    threadPool.Start(2);
        this_thread::sleep_for(chrono::seconds(3));
    threadPool.Stop();
    return 0;
}